#include "camera.h"

namespace TGO { 

        Camera& BasicCamera()
        {
                static Camera tgoBasicCamera;
                return tgoBasicCamera;
        }

}
/*
        camera
*/

Camera::Camera():mEyePos( 0, 0, -1000.0f ), mTargetPos( 0, 0, 0 )
{

}

void Camera::UpdateCamera()
{
    D3DXMATRIX V;
    D3DXVECTOR3 eye( mEyePos );
    D3DXVECTOR3 up( 0, 1, 0 );
    D3DXVECTOR3 target( mTargetPos );
    D3DXMatrixLookAtLH( &V, &eye, &target, &up );
    RenderFrame::GetD3DDevice()->SetTransform(D3DTS_VIEW, &V);      
}

void Camera::UpdateCamera( D3DXVECTOR2 orthoCenter )
{
	mEyePos.x = orthoCenter.x;
	mEyePos.y = orthoCenter.y;

	mTargetPos.x = orthoCenter.x;
	mTargetPos.y = orthoCenter.y;

	D3DXMATRIX V;
	D3DXVECTOR3 eye( mEyePos );
	D3DXVECTOR3 up( 0, 1, 0 );
	D3DXVECTOR3 target( mTargetPos );
	D3DXMatrixLookAtLH( &V, &eye, &target, &up );
	RenderFrame::GetD3DDevice()->SetTransform(D3DTS_VIEW, &V);      
}

void Camera::Move( D3DXVECTOR3 speed )
{
        const float delta = 1.0f;
        D3DXVec3Add( &mEyePos, &mEyePos, &( speed * delta ) );
        D3DXVec3Add( &mTargetPos, &mTargetPos, &( speed * delta ) );
        UpdateCamera();
}